package com.gtxc.kotlinmvvm.viewmodle

import android.util.Log
import androidx.lifecycle.MutableLiveData
import com.aleyn.mvvm.base.BaseViewModel
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.ToastUtils
import com.gtxc.kotlinmvvm.network.request.RegisterBean
import com.gtxc.kotlinmvvm.network.request.RequestTestBean
import com.gtxc.kotlinmvvm.utlis.BooleanObservableField
import com.gtxc.kotlinmvvm.utlis.StringObservableField

import com.mot.st.network.request.ApiNetWork

class RegisterViewModle : BaseViewModel(){

    //账户名
    val userName = MutableLiveData<String>()
    //密码
    val password1 = MutableLiveData<String>()
    //邀请码、
    var invitationCode=MutableLiveData<String>("1")
    //确认密码
    val password2 = MutableLiveData<String>()
    //验证码
    val code = MutableLiveData<String>()
    //是否显示明文密码（登录注册界面）
    var isRead = MutableLiveData<Boolean>()

    init {

    }
    fun getCode(requestTestBean: RequestTestBean){
        launchUI {
            val result = ApiNetWork.getInstance().Postcode(requestTestBean)
            LogUtils.e("----"+result)
            if (result.success){
                ToastUtils.showLong("发送成功")
                code.value=result.resultObj
            }else{
                ToastUtils.showLong("发送失败"+result.message)
            }
        }
    }
    fun getRegister(registerBean: RegisterBean){
        launchUI {
            val result = ApiNetWork.getInstance().postRegister(registerBean)
            LogUtils.e("----"+result)
            if (result.success){
                ToastUtils.showLong("注册成功，请登录！")
                Log.i("TAG", "getRegister: "+result)
            }else{
                ToastUtils.showLong("注册失败"+result.message)
            }
        }
    }

}